<?php
/**
 * Created by PhpStorm.
 * User: ye
 * Date: 2017/11/19
 * Time: 下午9:50
 */

namespace App;


use Illuminate\Database\Eloquent\Model;

class Book extends Model {

    // 从阿里云返回数据保存到数据库中
    public function aliyun2Book($data) {
        /*
         *  "title": "有理想就有疼痛",
        "subtitle": "中国当代文化名人访谈录",
        "pic": "http://api.jisuapi.com/isbn/upload/20161010/174050_28792.jpg",
        "author": "高晓春",
        "summary": "《有理想就有疼痛:中国当代文化名人访谈录》是一份关于当代中国文化的最真实底稿，收录了高晓春与白先勇、冯骥才、余华、莫言、余秋雨、陈忠实等20位当代中国文化大家的对话。通过近距离的访谈，展现了这些文化大家多彩的内心世界，也阐释了他们对生命、艺术、财富及文化的理解。",
        "publisher": "",
        "pubplace": "",
        "pubdate": "2013-1",
        "page": "256",
        "price": "29.00",
        "binding": "",
        "isbn": "9787212058937",
        "isbn10": "7212058939",
        "keyword": "",
        "edition": "",
        "impression": "",
        "language": "",
        "format": "",
        "class": ""
         */
        $this->title = $data->title;
        $this->subtitle = $data->subtitle;
        $this->pic = $data->pic;
        $this->author = $data->author;
        $this->summary = $data->summary;
        $this->publisher = $data->publisher;
        $this->pubplace = $data->pubplace;
        $this->pubdate = $data->pubdate;
        $this->page = $data->page;
        $this->price = $data->price;
        $this->binding = $data->binding;
        $this->isbn = $data->isbn;
        $this->isbn10 = $data->isbn10;
        $this->keyword = $data->keyword;
        $this->edition = $data->edition;
        $this->impression = $data->impression;
        $this->language = $data->language;
        $this->format = $data->format;
        $this->class = $data->class;

        return $this->save();
    }

    public function pivot() {
        return $this->belongsTo('App\BookUser', 'id', 'book_id');
    }
}